version 6.0 
#delimit ;

/* set up post files */

/* obtain temporary names for post file buffers */
tempname LK  LK5  ;

postfile `LK' 
nsim
bsiLKlfr bsiLKagr bsiLKenv bsiLKimm bsiLKpri bsiLKalc 
bl_LKlfr bl_LKagr bl_LKenv bl_LKimm bl_LKpri bl_LKalc 
blpLKlfr blpLKagr blpLKenv blpLKimm blpLKpri blpLKalc bconLKi

esiLKlfr esiLKagr esiLKenv esiLKimm esiLKpri esiLKalc 
el_LKlfr el_LKagr el_LKenv el_LKimm el_LKpri el_LKalc 
elpLKlfr elpLKagr elpLKenv elpLKimm elpLKpri elpLKalc econLKi

iLKnobs iLKss iLKdf iLKrss iLKrdf iLKF iLKRsq iLKaRsq iLKrmse  


bsmLKlfr bsmLKagr bsmLKenv bsmLKimm bsmLKpri bsmLKalc 
blrLKlfr blrLKagr blrLKenv blrLKimm blrLKpri blrLKalc 
blmLKlfr blmLKagr blmLKenv blmLKimm blmLKpri blmLKalc bconLKm

esmLKlfr esmLKagr esmLKenv esmLKimm esmLKpri esmLKalc 
elrLKlfr elrLKagr elrLKenv elrLKimm elrLKpri elrLKalc 
elmLKlfr elmLKagr elmLKenv elmLKimm elmLKpri elmLKalc econLKm

mLKnobs mLKss mLKdf mLKrss mLKrdf mLKF mLKRsq mLKaRsq mLKrmse  
using c:\stata\data\LK5set\lsproxEU2LK, replace
;   



postfile `LK5' 
nsim
bsiL5lfr bsiL5agr bsiL5env bsiL5imm bsiL5pri bsiL5alc 
bl_L5lfr bl_L5agr bl_L5env bl_L5imm bl_L5pri bl_L5alc 
blpL5lfr blpL5agr blpL5env blpL5imm blpL5pri blpL5alc bconL5i

esiL5lfr esiL5agr esiL5env esiL5imm esiL5pri esiL5alc 
el_L5lfr el_L5agr el_L5env el_L5imm el_L5pri el_L5alc 
elpL5lfr elpL5agr elpL5env elpL5imm elpL5pri elpL5alc econL5i

iL5nobs iL5ss iL5df iL5rss iL5rdf iL5F iL5Rsq iL5aRsq iL5rmse  

using c:\stata\data\LK5set\lsproxEU2LK5, replace
;   



/**** start of actual program code *****/

/*** reshape the data matrix ***/
reshape long ; 

/* Initialize relevant variables nsim */
scalar nsim=1 ;
initvar psymp mngsymp;
                    
/* *******    BEGIN ACTIVE SIMULATION ***** */
display "$S_TIME" ;
while nsim<=maxsim { ;


/* ** calculate the assimilated and contrasted perceptions ** */
/* SV */


replace psymp=66.1 - (0.44*dixlfrt + 0.19*dixagri +0.20*dixenvi +
         0.08*diximmi + 0.18*dixpriv + 0.19*dixalco) if (symp ~=.);
replace gsymp=psymp+19.56*invnorm(uniform()) ;


/*** time for regression runs ***/

/*** regression runs ***/
/* Lewis-King individual perception */
display 
"Simul data Lewis King style analysis -- individual perception";
regress gsymp  si2lfrt  si2agri  si2envi  si2immi  si2priv  si2alco
               rlnlfrt  rlnagri  rlnenvi  rlnimmi  rlnpriv  rlnalco 
               plnlfrt  plnagri  plnenvi  plnimmi  plnpriv  plnalco ;
matrix bLKi=get(_b) ;
matrix vce=get(VCE) ;
getstde vce 19;
matrix seLKi=std_errs ;
matrix LKires=(_result(1),_result(2),_result(3),_result(4),_result(5),
              _result(6),_result(7),_result(8),_result(9));

/* Lewis-King mean perceptions */
display 
"Simul data Lewis King style analysis -- mean perception";
regress gsymp  sm2lfrt  sm2agri  sm2envi  sm2immi  sm2priv  sm2alco
               rlnlfrt  rlnagri  rlnenvi  rlnimmi  rlnpriv  rlnalco 
               mlnlfrt  mlnagri  mlnenvi  mlnimmi  mlnpriv  mlnalco ;
matrix bLKm=get(_b) ;
matrix vce=get(VCE) ;
getstde vce 19;
matrix seLKm=std_errs ;
matrix LKmres=(_result(1),_result(2),_result(3),_result(4),_result(5),
              _result(6),_result(7),_result(8),_result(9));

post `LK'
nsim
bLKi[1,1] bLKi[1,2] bLKi[1,3] bLKi[1,4] bLKi[1,5] bLKi[1,6] 
bLKi[1,7] bLKi[1,8] bLKi[1,9] bLKi[1,10] bLKi[1,11] bLKi[1,12] 
bLKi[1,13] bLKi[1,14] bLKi[1,15] bLKi[1,16] bLKi[1,17] bLKi[1,18] 
bLKi[1,19] 
seLKi[1,1] seLKi[1,2] seLKi[1,3] seLKi[1,4] seLKi[1,5] seLKi[1,6] 
seLKi[1,7] seLKi[1,8] seLKi[1,9] seLKi[1,10] seLKi[1,11] seLKi[1,12] 
seLKi[1,13] seLKi[1,14] seLKi[1,15] seLKi[1,16] seLKi[1,17] seLKi[1,18] 
seLKi[1,19] 
LKires[1,1] LKires[1,2] LKires[1,3] LKires[1,4] LKires[1,5] 
         LKires[1,6] LKires[1,7] LKires[1,8] LKires[1,9] 
bLKm[1,1] bLKm[1,2] bLKm[1,3] bLKm[1,4] bLKm[1,5] bLKm[1,6] 
bLKm[1,7] bLKm[1,8] bLKm[1,9] bLKm[1,10] bLKm[1,11] bLKm[1,12] 
bLKm[1,13] bLKm[1,14] bLKm[1,15] bLKm[1,16] bLKm[1,17] bLKm[1,18] 
bLKm[1,19] 
seLKm[1,1] seLKm[1,2] seLKm[1,3] seLKm[1,4] seLKm[1,5] seLKm[1,6] 
seLKm[1,7] seLKm[1,8] seLKm[1,9] seLKm[1,10] seLKm[1,11] seLKm[1,12] 
seLKm[1,13] seLKm[1,14] seLKm[1,15] seLKm[1,16] seLKm[1,17] seLKm[1,18] 
seLKm[1,19] 
LKmres[1,1] LKmres[1,2] LKmres[1,3] LKmres[1,4] LKmres[1,5] 
         LKmres[1,6] LKmres[1,7] LKmres[1,8] LKmres[1,9]
;

/* Lewis-King individual perception five party analysis */
display 
"Simul data Lewis King style analysis -- individual perception 5 party";
regress gsymp  si2lfrt  si2agri  si2envi  si2immi  si2priv  si2alco
               rlnlfrt  rlnagri  rlnenvi  rlnimmi  rlnpriv  rlnalco 
               plnlfrt  plnagri  plnenvi  plnimmi  plnpriv  plnalco 
               if penalty<0.001;
matrix bL5i=get(_b) ;
matrix vce=get(VCE) ;
getstde vce 19;
matrix seL5i=std_errs ;
matrix L5ires=(_result(1),_result(2),_result(3),_result(4),_result(5),
              _result(6),_result(7),_result(8),_result(9));

post `LK5'
nsim
bL5i[1,1] bL5i[1,2] bL5i[1,3] bL5i[1,4] bL5i[1,5] bL5i[1,6] 
bL5i[1,7] bL5i[1,8] bL5i[1,9] bL5i[1,10] bL5i[1,11] bL5i[1,12] 
bL5i[1,13] bL5i[1,14] bL5i[1,15] bL5i[1,16] bL5i[1,17] bL5i[1,18] 
bL5i[1,19] 
seL5i[1,1] seL5i[1,2] seL5i[1,3] seL5i[1,4] seL5i[1,5] seL5i[1,6] 
seL5i[1,7] seL5i[1,8] seL5i[1,9] seL5i[1,10] seL5i[1,11] seL5i[1,12] 
seL5i[1,13] seL5i[1,14] seL5i[1,15] seL5i[1,16] seL5i[1,17] seL5i[1,18] 
seL5i[1,19] 
L5ires[1,1] L5ires[1,2] L5ires[1,3] L5ires[1,4] L5ires[1,5] 
         L5ires[1,6] L5ires[1,7] L5ires[1,8] L5ires[1,9] 
;


*no need to reshape wide ;

scalar nsim=nsim+1 ;
} ; /* **** end of while loop**** */

/* close post files */
postclose `LK' ;
postclose `LK5' ;
